package globalCode;

//Specific thread used by the TableHandler to update groups
public class TableHandlerThread extends ConnThread {
	
	
	private GroupConnections groupCon; //The group connection being analyzed
	TableHandlerContainer parentCont; //The container to report back to
	TableHandler handler; //The specific TableHandler to use
	
	public TableHandlerThread(TableHandlerContainer gcsTestApplet, GroupConnections gc, TableHandler th){
		parentCont = gcsTestApplet;
		setGroupCon(gc);
		handler = th;
	}
	
	//Runs all connections between users, using the TableHandler to update
	public void run(){
		
		int i = 0;
		int max = getGroupCon().getIDs().size()-1;
		parentCont.thtUsersInGroup(max); //Tells the container how many users are in the group being analyzed
		
		//While it's not told to stop and it's not done
		while(!stopBool && i!=-1){
			i = getGroupCon().splitGetCons(this); //Analyze one user's worth of connection 
			parentCont.thtUserFinished(); //Tell the container one user is completely done
		}
		if(stopBool){
			return;
		}
		parentCont.thtDisplay(getGroupCon().getRankings()); //Display the rankings on the parent container
		handler.update(getGroupCon().getGroupID(), getGroupCon().getFullRankings()); //Update all users changed by this thread in the database
		parentCont.thtGroupFinished(this); //Tell the container the group is finished being analyzed
	}

	public GroupConnections getGroupCon() {
		return groupCon;
	}

	public void setGroupCon(GroupConnections groupCon) {
		this.groupCon = groupCon;
	}
}
